package com.hspedu.spring.factory;

import com.hspedu.spring.bean.Monster;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: lihaojie
 * @Description: 实例工厂类
 * @DateTime: 2024/2/19 14:52
 **/
public class MyInstanceFactory {

    private Map<String, Monster> monster_map;

    // 通过普通代码块进行初始化
    {
        monster_map = new HashMap<>();
        monster_map.put("monster03", new Monster(300, "牛魔王~", "芭蕉扇"));
        monster_map.put("monster04", new Monster(400, "狐狸精~", "魅惑"));
    }

    // 写一个方法 返回monster对象
    public Monster getMonster(String key) {
        return monster_map.get(key);
    }

}
